package cn.fancy.sdk.utils;

import android.content.Context;
import android.os.Environment;
import cn.fancy.sdk.login.QdLoginCallback;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.HashMap;

public class CommMessage {

	private static String realtype = ""; // 实名认证类型
	// 防沉迷
	private static String cmCert = "";

	private final static String docdir = "/Android/data/code/systemMess/";

	private static String Devicemacfile = "signalmess.log";


	public static boolean canAutoLogin = true;

	// 记录登录面板、找回密码、绑定手机、实名认证窗口当前user、pass
	public static String currentUserName = "";
	public static String currentPassword = "";
	public static String currentRealmainUserName = "";
	public static String currentRealmainPassword = "";
	// 浮标闪屏url
	public static QdLoginCallback sLoginCallback = null;
	public static boolean isChangingAccount = true;
	// 找回手机号和验证码
	public static String sFindCode = null;
	public static String sFindUser = null;
	public static String sFindPass = null;
	public static boolean sBindAndReal;// 保存当前是否在绑定手机、实名
	public static boolean sifLoginViewNow = false;
	public static boolean sifReturnLoginView = false;// 标志位，点击返回键时回到登陆页
	public static boolean sifRealReturnLoginView = false;
	// 存放是否已经登录的状态
	public static boolean havedlogin = false;
	public static HashMap<String, String> mapRoleInformation= new HashMap<>();

	public static boolean getcanAutoLogin() {
		boolean canlog = true;
		if (canAutoLogin) {
			canAutoLogin = false;
		} else {
			canlog = false;
		}
		return canlog;
	}

	public static boolean isHavedlogin() {
		return havedlogin;
	}

	public static void setMacFile(String packagename) {
		if (packagename != null && !packagename.equals("")) {
			Devicemacfile = packagename + "_" + "signalmess.log";
		}
	}

	public static String getMacFile() {
		if (Devicemacfile == null || Devicemacfile.equals("")) {
			return "/Android/data/code/systemMess/signalmess.log";
		}
		return docdir + Devicemacfile;
	}
	
	public static void setRealType(String type) {
		realtype = type;
	}

	public static String getRealType() {
		if (realtype == null) {
			return "";
		}
		return realtype;
	}
	
	public static void setCmCert(String newCmCert) {
		cmCert = newCmCert;
	}

	public static String getCmCert() {
		return cmCert;
	}
	
	// 读文件内容, 参数2代码默认内容
	public static String getFileMess(final String filename,
			final String faultMess) {
		String filemess = faultMess;
		File filesign = new File(Environment.getExternalStorageDirectory()
				.getAbsoluteFile() + filename);
		try {
			BufferedReader br = new BufferedReader(new FileReader(filesign));
			String temp = null;
			StringBuilder sb = new StringBuilder();
			temp = br.readLine();
			while (temp != null) {
				sb.append(temp);
				temp = br.readLine();
			}
			filemess = sb.toString();
			br.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return filemess;
	}
	
	// 获取包的绝对路径
	public static String GetSdcardRootPath(Context sm_context) {
		if (sm_context == null) {
			return "";
		}

		String state = Environment.getExternalStorageState();
		String ret = "";

		if (Environment.MEDIA_MOUNTED.equals(state)
				|| Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
			File dir = sm_context.getExternalFilesDir(null);
			if (dir == null) {
				return "";
			}
			ret = dir.getAbsolutePath();
		} else {
			File dir = sm_context.getFilesDir();
			if (dir == null) {
				return "";
			}
			ret = dir.getAbsolutePath();
		}
		// 以上获取安装包数据存放绝对路径

		if (!ret.endsWith("/")) {
			ret += '/';
		}
		return ret;
	}
	
}
